<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.base.myproject.client.jdbc.*" %>
<%@ page language="java" import="com.base.myproject.server.*" %>
<%@ page language="java" import="com.base.myproject.client.jdbc.DataSet" %>
<%@ page language="java" import="com.base.myproject.server.tools.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="report.css" rel="stylesheet" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>排班</title>
</head>
<%
	String data = request.getParameter("data");
	String[] datas = data.split("_");
	String s_date = datas[0];
	String dep_code = datas[1];
	String s_name = null;
	if (datas.length == 3) {
		s_name = datas[2];
	}
	String where = " 1=1 ";
	if (s_date != null) {
		where = " and CONVERT(varchar(7),ym,120)='"
			+ s_date + "'";
	}
	int year = Integer.parseInt(s_date.substring(0,4));
	int month = Integer.parseInt(s_date.substring(s_date.length() - 2));
	int days = 0;
	if(month != 2) {
		switch(month) {
		   case 1:
		   case 3:
		   case 5:
		   case 7:
		   case 8:
		   case 10:
		   case 12:days = 31 ;break;
		   case 4:
		   case 6:
		   case 9:
		   case 11:days = 30;
		}
	}else{
		   if(year%4==0 && year%100!=0 || year%400==0)
			   days = 29;
		   else  days = 28;
	}
	
	where += " and depCode = '"+dep_code+"'";
	if (s_name != null) {
		where += " and (hr_Attendance_schedule.bcode = '"+s_name+"' or hr_Attendance_schedule.bname like '%" + s_name + "%')";
	}
	String sql = "select *,employno from hr_Attendance_schedule,bcode_job where hr_Attendance_schedule.bcode = bcode_job.bcode " + where + " order by hr_Attendance_schedule.icode";
	
	System.out.println(sql);
	
	DataSetTool DST = new DataSetTool();
	DataSet result = DST.getDataSet(sql);
	DataSet department = DST.getDataSet("select name from systeminfo where id = '"+dep_code+"'");
	String workbatchSql = "select batchName,batchNo,bgnTime1,endTime1,bgnTime2,endTime2 from hr_Attendance_workbatch where depCode = '"+dep_code+"'";
	DataSet workbatch = DST.getDataSet(workbatchSql);
%>
<body>
	<p align='center'><font size='4'><b>部门排班表</b></font></p>
	<p align="left">查询年月：<%=s_date %> 部门：<%=department.getValue(0,"name") %></p>
	<table style="border-collapse: collapse; font-size: 10px;"
	cellspacing="0" cellpadding="0" border="1" width="100%"
	bordercolordark="#CCCCCC" bordercolorlight="#CCCCCC"
	style="border-color:#000000; "> 
		<tr bgcolor="#e8e8e0" align="center">
			<td width="5%">姓名</td ><td>员工编号</td>
			<td width="3%">1</td><td width="3%">2</td><td width="3%">3</td><td width="3%">4</td><td width="3%">5</td><td width="3%">6</td>
			<td width="3%">7</td><td width="3%">8</td><td width="3%">9</td><td width="3%">10</td><td width="3%">11</td><td width="3%">12</td><td width="3%">13</td><td width="3%">14</td><td width="3%">15</td><td width="3%">16</td><td width="3%">17</td>
			<td width="3%">18</td><td width="3%">19</td><td width="3%">20</td><td width="3%">21</td><td width="3%">22</td><td width="3%">23</td><td width="3%">24</td><td width="3%">25</td><td width="3%">26</td><td width="3%">27</td>
			<%
				if(days == 28){
			%>	
				<td width="3%">28</td>
			<%
				}else if(days == 29){
			%>
				<td width="3%">28</td><td width="3%">29</td>
			<%		
				}else if(days == 30){
			%>
				<td width="3%">28</td><td width="3%">29</td><td width="3%">30</td>
			<%
				}else if(days == 31){
			%>
				<td width="3%">28</td><td width="3%">29</td><td width="3%">30</td><td width="3%">31</td>
			<%		
				}
			%>
		</tr>
		<%
			for(int i = 0;i < result.getRowCount();i++){
		%>		
			<tr align="center">
				<td><%=result.getValue(i,"bname") %></td>
				<td><%=result.getValue(i,"employno") %></td>
				<td><%=result.getValue(i,"r1") == null ? " " : result.getValue(i,"r1") %></td>
				<td><%=result.getValue(i,"r2") == null ? " " : result.getValue(i,"r2") %></td>
				<td><%=result.getValue(i,"r3") == null ? " " : result.getValue(i,"r3") %></td>
				<td><%=result.getValue(i,"r4") == null ? " " : result.getValue(i,"r4") %></td>
				<td><%=result.getValue(i,"r5") == null ? " " : result.getValue(i,"r5") %></td>
				<td><%=result.getValue(i,"r6") == null ? " " : result.getValue(i,"r6") %></td>
				<td><%=result.getValue(i,"r7") == null ? " " : result.getValue(i,"r7") %></td>
				<td><%=result.getValue(i,"r8") == null ? " " : result.getValue(i,"r8") %></td>
				<td><%=result.getValue(i,"r9") == null ? " " : result.getValue(i,"r9") %></td>
				<td><%=result.getValue(i,"r10") == null ? " " : result.getValue(i,"r10") %></td>
				<td><%=result.getValue(i,"r11") == null ? " " : result.getValue(i,"r11") %></td>
				<td><%=result.getValue(i,"r12") == null ? " " : result.getValue(i,"r12") %></td>
				<td><%=result.getValue(i,"r13") == null ? " " : result.getValue(i,"r13") %></td>
				<td><%=result.getValue(i,"r14") == null ? " " : result.getValue(i,"r14") %></td>
				<td><%=result.getValue(i,"r15") == null ? " " : result.getValue(i,"r15") %></td>
				<td><%=result.getValue(i,"r16") == null ? " " : result.getValue(i,"r16") %></td>
				<td><%=result.getValue(i,"r17") == null ? " " : result.getValue(i,"r17") %></td>
				<td><%=result.getValue(i,"r18") == null ? " " : result.getValue(i,"r18") %></td>
				<td><%=result.getValue(i,"r19") == null ? " " : result.getValue(i,"r19") %></td>
				<td><%=result.getValue(i,"r20") == null ? " " : result.getValue(i,"r20") %></td>
				<td><%=result.getValue(i,"r21") == null ? " " : result.getValue(i,"r21") %></td>
				<td><%=result.getValue(i,"r22") == null ? " " : result.getValue(i,"r22") %></td>
				<td><%=result.getValue(i,"r23") == null ? " " : result.getValue(i,"r23") %></td>
				<td><%=result.getValue(i,"r24") == null ? " " : result.getValue(i,"r24") %></td>
				<td><%=result.getValue(i,"r25") == null ? " " : result.getValue(i,"r25") %></td>
				<td><%=result.getValue(i,"r26") == null ? " " : result.getValue(i,"r26") %></td>
				<td><%=result.getValue(i,"r27") == null ? " " : result.getValue(i,"r27") %></td>
				<%
					if(days == 28){
				%>	
					<td><%=result.getValue(i,"r28") == null ? " " : result.getValue(i,"r28") %></td>
				<%
					}else if (days == 29){
				%>
					<td><%=result.getValue(i,"r28") == null ? " " : result.getValue(i,"r28") %></td>
					<td><%=result.getValue(i,"r29") == null ? " " : result.getValue(i,"r29") %></td>	
				<%		
					}else if(days == 30){
				%>
					<td><%=result.getValue(i,"r28") == null ? " " : result.getValue(i,"r28") %></td>
					<td><%=result.getValue(i,"r29") == null ? " " : result.getValue(i,"r29") %></td>
					<td><%=result.getValue(i,"r30") == null ? " " : result.getValue(i,"r30") %></td>
				<%
					}else if(days == 31){
				%>
					<td><%=result.getValue(i,"r28") == null ? " " : result.getValue(i,"r28") %></td>
					<td><%=result.getValue(i,"r29") == null ? " " : result.getValue(i,"r29") %></td>
					<td><%=result.getValue(i,"r30") == null ? " " : result.getValue(i,"r30") %></td>
					<td><%=result.getValue(i,"r31") == null ? " " : result.getValue(i,"r31") %></td>
				<%		
					}
				%>
			</tr>
		<%	}%>
	</table>
	<p></p>
	<table style="border-collapse: collapse" cellspacing="0" cellpadding="0" border="1" width="100%" bordercolordark="#CCCCCC" bordercolorlight="#CCCCCC" style="line-height: 150%;border-color:#000000;">
		<%for(int i = 0;i < workbatch.getRowCount();i++){
			if(i % 4 == 0){
			%>
				<tr>
			<%} %>
					<td><%=workbatch.getValue(i,"batchName") %>
						(<%=workbatch.getValue(i,"batchNo") %>)
						&nbsp;<%=workbatch.getValue(i,"bgnTime1") == null? "" : workbatch.getValue(i,"bgnTime1")+" -"%> 
						 <%=workbatch.getValue(i,"endTime1") == null ? "" :  workbatch.getValue(i,"endTime1")%>
						 &nbsp;<%=workbatch.getValue(i,"bgnTime2") == null ? "" :  "," + workbatch.getValue(i,"bgnTime2") + " -"%>
						 <%=workbatch.getValue(i,"endTime2") == null ? "" : workbatch.getValue(i,"endTime2")%>
					</td>
			<% if((i+1) % 4 == 0){
			%>
				</tr>
			<%} %>
		<%} %>	
	</table>
	<br></br>
	<p></p>
	<p align="center">考勤员:___________________部门主管:___________________人力资源部:_________________</p>
</body>
</html>